pub fn convert_base(num_str: &str, to_base: u32) -> String {
    // 解析输入格式 `<number>(<from_base>)`
    let parts: Vec<&str> = num_str.trim_end_matches(')').split('(').collect();

    if parts.len() != 2 {
        return "Invalid format. Use `<number>(<from_base>)` format.".to_string();
    }

    let number_str = parts[0];
    let from_base: u32 = match parts[1].parse() {
        Ok(base) if (2..=16).contains(&base) => base,
        _ => return "Invalid base. Base must be between 2 and 16.".to_string(),
    };

    // 将源进制的字符串转换为十进制数
    let decimal_value = match u32::from_str_radix(number_str, from_base) {
        Ok(val) => val,
        Err(_) => return "Invalid number for the given base.".to_string(),
    };

    // 将十进制数转换为目标进制字符串
    decimal_to_base(decimal_value, to_base)
}

/// 辅助函数：将十进制数转换为指定进制的字符串
fn decimal_to_base(mut num: u32, base: u32) -> String {
    let digits = "0123456789abcdef";
    let mut result = String::new();

    if num == 0 {
        return "0".to_string();
    }

    while num > 0 {
        let remainder = (num % base) as usize;
        result.insert(0, digits.chars().nth(remainder).unwrap());
        num /= base;
    }

    result
}